package com.dgshanger.sanhxiaofeisc.ui.home.activity

import android.os.Bundle
import com.amap.api.maps2d.model.LatLng
import com.amap.api.maps2d.AMap
import com.amap.api.maps2d.CameraUpdateFactory
import com.amap.api.maps2d.model.BitmapDescriptorFactory
import com.amap.api.maps2d.model.Marker
import com.amap.api.maps2d.model.MarkerOptions
import com.dgshanger.sanhxiaofeisc.R
import com.xx.baseuilibrary.mvp.BaseMvpViewActivity
import kotlinx.android.synthetic.main.activity_map.*

/**
 * Created by JacobHHH on 2018/5/9.
 */
class MapActivity : BaseMvpViewActivity() {

    private lateinit var mLatitude : String
    private lateinit var mLongitude : String
    private  var mAMap : AMap? = null

    override fun getActivityLayoutId(): Int = R.layout.activity_map

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mapView.onCreate(savedInstanceState)

        if (mAMap == null) {
            mAMap = mapView.map
        }
        //隐藏缩放按钮
        mAMap!!.getUiSettings().setZoomControlsEnabled(false)//实例化UiSettings类对象
        initMap()
    }

    override fun initData() {
        mLatitude = intent.getStringExtra("latitude")
        mLongitude = intent.getStringExtra("longitude")

    }

    private lateinit var mLocationMarker: Marker
    private fun initMap() {
        val latLng = LatLng(mLatitude.toDouble(), mLongitude.toDouble())//取出经纬度
        mLocationMarker = mAMap!!.addMarker(MarkerOptions()
                .position(latLng).icon(BitmapDescriptorFactory.fromResource(R.mipmap.center_address)))
        //mAMap!!.moveCamera(CameraUpdateFactory.changeLatLng(latLng))
        mAMap!!.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 20.0f))


    }

    override fun initEvent() {

    }

    override fun onResume() {
        super.onResume()
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mapView.onResume()
    }

    override fun onPause() {
        super.onPause()
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mapView.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mapView.onDestroy()
    }

    override fun onSaveInstanceState(outState: Bundle?) {
        super.onSaveInstanceState(outState)
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mapView.onSaveInstanceState(outState)
    }


}